
import sqlalchemy
from sqlalchemy.sql import text
from sqlalchemy import select

from model.remember import Remember


# 通过 id 查看结果
async def find_by_id(conn):
    # 因为记住密码只有一条记录，id 都是 1。固定写 1 即可
    query = select(Remember).filter(Remember.id == 1)
    result = await conn.execute(query)
    remember = result.fetchone()
    return remember

# 插入记录
async def insert(conn, username, password):
    query = sqlalchemy.insert(Remember).values(
        username=username, password=password)
    await conn.execute(query)

# 更新记住的密码
async def update(conn, username, password):
    query = sqlalchemy.update(Remember).where(Remember.id == 1).values(
        username=username, password=password)
    await conn.execute(query)
